<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Linux 安装 Nginx | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Linux 安装 Nginx 从官网下载 Nginx 安装包     解压到本地  命令行解压  1234# 切换到包含nginx压缩包的文件夹cd home&#x2F;pi&#x2F;Downloads# 进行解压缩tar -zxvf nginx-1.19.7.tar.gz   实用工具解压   进入终端, 切换到nginx解压后的文件夹中   1cd &#x2F;home&#x2F;pi&#x2F;Downloads&#x2F;nginx-1.19.7">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 安装 Nginx">
<meta property="og:url" content="https://lummer.gitee.io/hexo/2021/02/25/Linux%20%E5%AE%89%E8%A3%85%20Nginx/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Linux 安装 Nginx 从官网下载 Nginx 安装包     解压到本地  命令行解压  1234# 切换到包含nginx压缩包的文件夹cd home&#x2F;pi&#x2F;Downloads# 进行解压缩tar -zxvf nginx-1.19.7.tar.gz   实用工具解压   进入终端, 切换到nginx解压后的文件夹中   1cd &#x2F;home&#x2F;pi&#x2F;Downloads&#x2F;nginx-1.19.7">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210225144124.png">
<meta property="og:image" content="http://cdn.baishew.com/hidove-images/2021/02/25/60374d8387e1e.jpg">
<meta property="article:published_time" content="2021-02-25T07:02:47.403Z">
<meta property="article:modified_time" content="2021-09-20T10:10:11.660Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210225144124.png">
  
    <link rel="alternate" href="/hexo/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/hexo/css/style.css">

<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/hexo/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/hexo/">Home</a>
        
          <a class="main-nav-link" href="/hexo/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/hexo/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://lummer.gitee.io/hexo"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Linux 安装 Nginx" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/hexo/2021/02/25/Linux%20%E5%AE%89%E8%A3%85%20Nginx/" class="article-date">
  <time datetime="2021-02-25T07:02:47.403Z" itemprop="datePublished">2021-02-25</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Linux 安装 Nginx
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Linux-安装-Nginx"><a href="#Linux-安装-Nginx" class="headerlink" title="Linux 安装 Nginx"></a>Linux 安装 Nginx</h3><ol>
<li>从官网下载 Nginx 安装包</li>
</ol>
<img src="https://cdn.jsdelivr.net/gh/Lummer-Li/image-bucket/image/20210225144124.png" alt="image-20210225144124679" style="zoom:60%;" />

<ol start="2">
<li><p>解压到本地</p>
<ul>
<li>命令行解压</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 切换到包含nginx压缩包的文件夹</span></span><br><span class="line">cd home/pi/Downloads</span><br><span class="line"><span class="meta">#</span><span class="bash"> 进行解压缩</span></span><br><span class="line">tar -zxvf nginx-1.19.7.tar.gz</span><br></pre></td></tr></table></figure>

<ul>
<li>实用工具解压</li>
</ul>
</li>
<li><p>进入终端, 切换到nginx解压后的文件夹中</p>
</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd /home/pi/Downloads/nginx-1.19.7</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>安装前置依赖, 进入终端</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install gcc</span><br><span class="line">sudo apt-get install libpcre3 libpcre3-dev</span><br><span class="line">sudo apt-get install zlib1g zlib1g-dev</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>进行Nginx配置, 进入终端</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">./configure</span><br><span class="line">make</span><br><span class="line">sudo make install</span><br><span class="line"><span class="meta">#</span><span class="bash"> 最终会在/usr/<span class="built_in">local</span>文件夹中生成一个nginx文件夹, 里面会有配置文件</span></span><br></pre></td></tr></table></figure>

<ol start="6">
<li>启动nginx</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 切换到/usr/<span class="built_in">local</span>/nginx/sbin文件夹中</span></span><br><span class="line">cd /usr/local/nginx/sbin</span><br><span class="line">./nginx</span><br></pre></td></tr></table></figure>

<ol start="7">
<li>nginx常用命令</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 启动nginx</span></span><br><span class="line">./nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> 关闭nginx</span></span><br><span class="line">./nginx -s stop   或者   ./nginx -s quit</span><br><span class="line"><span class="meta">#</span><span class="bash"> 重启nginx</span></span><br><span class="line">./nginx -s reload</span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看nginx进程</span></span><br><span class="line">ps aux|grep nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> nginx开机自启动</span></span><br><span class="line">vim /etc/rc.local</span><br><span class="line"><span class="meta">#</span><span class="bash"> 文件底部加上 /usr/<span class="built_in">local</span>/nginx/sbin/nginx</span></span><br></pre></td></tr></table></figure>

<ol start="8">
<li>Nginx 相关文件路径</li>
</ol>
<img src="http://cdn.baishew.com/hidove-images/2021/02/25/60374d8387e1e.jpg" alt="截屏2021-02-25 下午2.52.29" style="zoom:50%;" />


      
    </div>
    <footer class="article-footer">
      <a data-url="https://lummer.gitee.io/hexo/2021/02/25/Linux%20%E5%AE%89%E8%A3%85%20Nginx/" data-id="cktshq5a10002du9lg9q7aw36" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/hexo/2021/03/02/Mac%E5%AE%89%E8%A3%85Redis%EF%BC%8C%E5%8E%9F%E6%9D%A5%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B9%88%E7%AE%80%E5%8D%95/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          使用Homebrew安装Redis
        
      </div>
    </a>
  
  
    <a href="/hexo/2021/02/24/Utils/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Utils</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/09/">September 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/08/">August 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/03/">March 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/02/">February 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/01/">January 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/hexo/2021/09/15/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/hexo/2021/08/20/Mac%20%E5%85%A8%E5%B1%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E9%9A%90%E8%97%8F%E7%A8%8B%E5%BA%8F%E5%9D%9E/">Mac 全屏时自动隐藏程序坞</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/29/Mac%E7%B3%BB%E7%BB%9F%E4%B8%AD%E7%9A%84.DS_Store/">Mac系统中的.DS_Store</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/21/Markdown/">Markdown</a>
          </li>
        
          <li>
            <a href="/hexo/2021/07/11/Github%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99%EF%BC%8C%E8%A7%A3%E5%86%B3Github%E8%AE%BF%E9%97%AE%E7%9A%84%E7%A5%9E%E5%99%A8/">Github国内镜像网站，解决Github访问的神器</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/hexo/" class="mobile-nav-link">Home</a>
  
    <a href="/hexo/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/hexo/fancybox/jquery.fancybox.css">

  
<script src="/hexo/fancybox/jquery.fancybox.pack.js"></script>




<script src="/hexo/js/script.js"></script>




  </div>
</body>
</html>